package com.example.classes;

import java.io.Serializable;
import java.util.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Environment;
import com.google.gson.annotations.Expose;

/**
 * @author      Alexander Huynh <a.huynh @ gatech.edu>
 * @version     1.0
 * @since       2013-02-28
 */
public class Item implements Serializable
{
    @Expose
	private final String name;
    @Expose
	private final String description;
    @Expose
	private final String category;
    @Expose
    private final double lat;
    @Expose
    private final double lon;
    @Expose
	private boolean state;       //state=true for found else lost item
    @Expose
    private boolean resolve;
    @Expose
	private final boolean lookingFor;
    @Expose
	private final double reward;


    @Expose
	private final Date date;

    public boolean equals(Object obj)
    {
        if (!(obj instanceof Item))
        {
            return false;
        }
        else
        {
            Item that = (Item) obj;
            return this.name.equals(that.name) && this.description.equals(that.description) && this.category.equals(that.category) &&
                    this.state == (that.state) && this.lookingFor == (that.lookingFor) && this.reward == (that.reward) && this.date.equals(that.date) && this.date.equals(that.date);
        }
    }


    public boolean isLookingFor() {
        return lookingFor;
    }

    public String getCategory() {
        return category;
    }

    public String getDescription() {
        return description;
    }

    public Date getDate() {
        return date;
    }

    public double getReward() {
        return reward;
    }

    public Location getLocation() {
        Location location = new Location("Dummy Provider");
        location.setLatitude(lat);
        location.setLongitude(lon);
        return location;
    }

    public boolean isState() {
        return state;
    }
    public boolean isResolve(){
        return resolve;
    }

    public void setState(boolean state){
        this.state = state;
    }
    public void setResolve(){
        resolve = true;
    }

    public String getName() {
        return name;
    }

    public double getLat()
    {
        return lat;
    }

    public double getLon()
    {
        return lon;
    }

    /**
	* Constructor
	* Instantiates and sets values.
	* @param name			name of Item
	* @param description	description of Item
	* @param category		category of Item; uses an enum
	* @param location		location of item; uses Location class
	* @param lookingFor		true if being looked for, false if found
	* @param reward			reward for finding Item in USD
	* @param date			date this Item was created
	* @param iconPath		path to	an image of the Item
	* @param member			owner of the Item
	*/
    public Item(String name, String description, String category, Location location,
    			boolean lookingFor, double reward, Date date, String iconPath, Member member)
    {
        String Filepath = Environment.getExternalStorageDirectory()+iconPath;
		this.name = name;
		this.description = description;
		this.category = category;
        this.lat = location.getLatitude();
        this.lon = location.getLongitude();
        this.state = false;
        this.resolve = false;
		this.lookingFor = lookingFor;
		this.reward = reward;
		this.date = date;
        Bitmap picture = BitmapFactory.decodeFile(Filepath);
    }

    @Override
    public String toString()
    {
        return name;
    }
}